package cn.tom.org.service.impl;

import cn.tom.org.mapper.EmployeeMapper;
import cn.tom.org.pojo.domain.Employee;
import cn.tom.org.pojo.query.EmployeeQuery;
import cn.tom.org.service.EmployeeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public Employee getOne(Long id) {
        return employeeMapper.selectById(id);
    }

    @Override
    public List<Employee> getAll() {
        return employeeMapper.selectList(null);
    }

    @Override
    public PageInfo<Employee> queryPage(EmployeeQuery query) {
        PageHelper.startPage(query.getCurrentPage(),query.getPageSize());
        List<Employee> list =employeeMapper.quaryPage(query);
        return new PageInfo<Employee>(list);
    }

    @Override
    @Transactional
    public void add(Employee employee) {
        employeeMapper.insert(employee);
    }

    @Override
    @Transactional
    public void update(Employee employee) {
        employeeMapper.updateById(employee);
    }


    @Override
    @Transactional
    public void delete(Long id) {
        employeeMapper.deleteById(id);
    }

    @Override
    @Transactional
    public void patchDelete(List<Long> ids) {
        employeeMapper.deleteBatchIds(ids);
    }
}
